const HtmlWebpackPlugin = require('html-webpack-plugin'); //加载HTML
const CleanWebpackPlugin = require('clean-webpack-plugin');//清空文件
const ExtractTextPlugin = require("extract-text-webpack-plugin");//加载css
const CopyWebpackPlugin = require("copy-webpack-plugin");//拷贝资源
var path = require('path');
module.exports = {
	entry: {
		"indexts": __dirname + "/src/ts_template/index.tsx",
		"index": __dirname + "/src/index.js",
		"test": __dirname + "/src/test/test.ts"
	},
	devtool: 'eval-source-map', //配置生成Source Maps，选择合适的选项   source-map eval-source-map
	module: {
		rules: [
		{
			test: /\.(scss|css|less)$/,
			exclude: /^node_modules$/, //加载css
			use: [
            'style-loader',
            'css-loader'
          ]
		},{
            test: /\.(js|jsx)$/,
            exclude: /^node_modules$/,
			loader: "babel-loader",
			options: {
				presets: ["es2015","react","stage-0"],//jsx 必须加上react参数 否则jsx编译不通过
				plugins: [
					["import", {
						libraryName: 'antd',
						style: "css"
					}]
				]
			}
        },{
            test: /\.(ts|tsx)$/,
            exclude: /^node_modules$/,
			loader: "ts-loader",
			options: {
				presets: ["react"]
			}
        },{
			test: /\.(png|svg|jpg|gif)$/, //加载图片
			exclude: /^node_modules$/,
			use: ['file-loader']
		}, {
			test: /\.(woff|woff2|eot|ttf|otf)$/, //加载字体
			exclude: /^node_modules$/,
			use: [
				'file-loader'
			]
		}]
	},
	plugins: [
		// new CleanWebpackPlugin(["dist"]),
		new ExtractTextPlugin("styles.css"),
		new CopyWebpackPlugin([{
			from: __dirname + '/src/fatchData',
			to:__dirname + '/dist/fatchData'
		}]),
		new HtmlWebpackPlugin({
			filename: "hello.html",
			template: "./src/index.html",
			inject: true
		})
	],
	output: {
		path: __dirname + "/dist",
		publicPath: "./",
		filename: "[name].js" //打包后输出文件的文件名
	},
	watch:true,
	devServer: {//配置服务器
		contentBase: path.join(__dirname, "/dist"),
		compress: true,
		host:"localhost",
		hot:true,
		inline:true,
		open:true,//打开浏览器
		openPage:'hello.html',
		watchContentBase: true,
		port: 9000
	}
}